package com.fyyg.common.wechat;

import com.fyyg.common.fyconst.PLATFORM;
import com.fyyg.common.util.PropertiesUtil;

import java.util.Properties;

/**
 * @author hang.ouyang
 * @date 2016-04-09 17:37
 */
public class WeChatObject {

    private static Properties wxProperties;
    private static String evn;
    //商户端
    public static String MCH_APPID ;
    public static String MCH_MCHID ;
    public static String MCH_KEY ;
    public static String MCH_FEEYPE ;
    public static String MCH_NATIVE_TRADETYPE ;
    public static String MCH_JS_TRADETYPE ;
    public static String MCH_APP_TRADETYPE ;
    public static String MCH_APPSECRET ;
    public static String MCH_PARTNERID ;
    
    
    
    // 微信登陆
    public static String SNSAPI_USERINFO_URL ;
    public static String ACCESS_TOKEN_URL ;
    public static String GET_USER_INFO_URL ;
    
    //APP支付
    public static String MCH_APP_APPID ;
    public static String MCH_APP_KEY ;
    
    // 微信登陆回调地址
    public static String LOGIN_NOTIFY_URL ;
    
    public static String WX_DOMAIN ;
    


    public static String getNotifyUrl(PLATFORM platform){
        if(platform == PLATFORM.WX){
           return  wxProperties.getProperty("WX_NOTIFY_URL");
        }else if(platform == PLATFORM.PC){
            return  wxProperties.getProperty("PC_NOTIFY_URL");
        }else if(platform==PLATFORM.APPLL){
        	 return  wxProperties.getProperty("APPLL_NOTIFY_URL");
        }
        else{
            return  wxProperties.getProperty("APP_NOTIFY_URL");
        }
    }


    public static String getEvn() {
        return evn;
    }
    public void setEvn(String evn) {
        WeChatObject.evn = evn;
        reloadProp();
    }
    
    private void reloadProp(){
    	if(getEvn() != null && !getEvn().equals("product")){
    		wxProperties = PropertiesUtil.getProperties("wx_test.properties");
    	}else{
    		wxProperties = PropertiesUtil.getProperties("wx.properties");
    	}
    	init();
    }
    
    private void init(){
    	 //商户端
	    MCH_APPID =  wxProperties.getProperty("MCH_APPID");
	    MCH_MCHID =  wxProperties.getProperty("MCH_MCHID");
	    MCH_KEY =  wxProperties.getProperty("MCH_KEY");
	    MCH_FEEYPE =  wxProperties.getProperty("MCH_FEETYPE");
	    MCH_NATIVE_TRADETYPE =  wxProperties.getProperty("MCH_NATIVE_TRADETYPE");
	    MCH_JS_TRADETYPE =  wxProperties.getProperty("MCH_JS_TRADETYPE");
	    MCH_APP_TRADETYPE =  wxProperties.getProperty("MCH_APP_TRADETYPE");
	    MCH_APPSECRET =  wxProperties.getProperty("APPSECRET");
	    MCH_PARTNERID =  wxProperties.getProperty("MCH_PARTNETID");
	    
	    // 微信登陆
	    SNSAPI_USERINFO_URL =  wxProperties.getProperty("SNSAPI_USERINFO_URL");
	    ACCESS_TOKEN_URL =  wxProperties.getProperty("ACCESS_TOKEN_URL");
	    GET_USER_INFO_URL =  wxProperties.getProperty("GET_USER_INFO_URL");
	    
	    //APP支付
	    MCH_APP_APPID =  wxProperties.getProperty("MCH_APP_APPID");
	    MCH_APP_KEY =  wxProperties.getProperty("MCH_APP_KEY");
	    
	    // 微信登陆回调地址
	    LOGIN_NOTIFY_URL =  wxProperties.getProperty("LOGIN_NOTIFY_URL");
	    
	    WX_DOMAIN =  wxProperties.getProperty("WX_DOMAIN");
    }
    
}
